<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>每日一句</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    html,
    body,
    #root {
      height: 100%;
    }

    .mask {
      position: absolute;
      background-color: rgba(0, 0, 0, 0.3);
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
    }

    h1 {
      color: rgb(255, 255, 255, 1);
      font-size: 2.4rem;
    }

    p {
      color: rgb(255, 255, 255, .9);
      font-size: 2rem;
      letter-spacing: 5px;
    }

    main {
      position: absolute;
      top: 20%;
      left: 40%;
    }
  </style>
</head>

<body>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/dayjs/1.10.6/dayjs.min.js"></script>
  <div id="root"></div>
  <script>
    let time = null
    function loadData() {
      time = dayjs().format('YYYY-MM-DD')
      $.ajax({
        url: 'http://sentence.iciba.com/index.php',
        dataType: 'jsonp',
        data: {
          c: "dailysentence",
          m: "getdetail",
          title: time
        },
        success(data) {
          let div = $('#root')
          div.css(
            { background: `url(${data.picture2}) center/cover no-repeat` }
          )
          div.html(`<div class='mask'></div><main><h1>${data.content}</h1><p>${data.note}</p></main>`)
        }
      })
    }
    loadData()
    setInterval(() => {
      const current = dayjs().format('YYYY-MM-DD')
      if (time !== current) {
        loadData()
      } else {
        loadData()
      }
    }, 60 * 1000 * 60)
  </script>

</body>

</html>